/*
 * Copyright 2010 David de Mingo
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.shalma.model;

import org.shalma.internal.reflection.IdGenerator;

/**
 * <p>
 * In a object system is useful to distinguish between entities (reference
 * objects) and value objects. In a persistence system, this difference is
 * important because entities have a different lifecycle and treatement than
 * values.
 * </p>
 * 
 * <h1>Entity</h1>
 * 
 * <p>
 * Entities have life cycles that can radically change their form and content,
 * but a thread of continuity must be maintained. Their class definitions,
 * responsibilities, attributes, and associations should revolve around who they
 * are, rather than the particular attributes they carry.
 * </p>
 * 
 * <p>
 * Identity is not intrinsic to a thing in the world; it is a meaning
 * superimposed because it is useful. In fact, the same real-world thing might
 * or might not be represented as an entity in a domain model. Identity is a
 * subtle and meaningful attribute of objects, which can't be turned over to the
 * automatic features of the language.
 * </p>
 * 
 * <h1>Value object</h1>
 * 
 * <p>
 * A value object is an object that represents a descriptive aspect of the
 * domain with no conceptual identity.
 * </p>
 * 
 * <p>
 * Value objects are instantiated to represent elements of the design that we
 * care about only for what they are, not who or which they are - they base it's
 * notion of equality on field values within the class.
 * </p>
 * 
 */
@Id("9NnTCHvIRBqoep44ctc08w")
public abstract class Entity {

	private Key<?> key;

	private long version;

	public Entity() {
		key = new Key<Entity>();
	}

	public Key<?> getKey() {
		return key;
	}

	public long getVersion() {
		return version;
	}

	public static final class Key<E extends Entity> {

		private byte[] entityId;

		Key() {
			entityId = IdGenerator.make(20);
		}

		public byte[] getEntityId() {
			return entityId;
		}
	}
}
